﻿using Common.Util.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Common.Test.Type
{
    [TestClass]
    public class RegexTest
    {
        [TestMethod]
        public void TestEmailRegex()
        {
            var exreg = RegexValidation.Email;
            //Valid email address
            Assert.IsTrue(Regex.IsMatch("\"sdas\".\"sdas\".xdqqw@đấ_-ss.x-_x", exreg));
            Assert.IsTrue(Regex.IsMatch("prettyandsimple@example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("very.common@example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("a.little.lengthy.but.fine@dept.example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("disposable.style.email.with+symbol@example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("other.email-with-dash@example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("\"much.more unusual\"@example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("\"very.unusual.@.unusual.com\"@example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("\"very.(),:;<>[]\\\".VERY.\\\"very@\\\\ \\\"very\\\".unusual\"@strange.example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("a#!$%&'*+-/=?^_`{}|~@example.org", exreg));
            Assert.IsTrue(Regex.IsMatch("\"()<>[]:,;@\\\".!#$%&'*+-/=?^_`{}| ~.a\"@example.org", exreg));
            Assert.IsTrue(Regex.IsMatch("\" \"@example.org", exreg));
            Assert.IsTrue(Regex.IsMatch("üñîçøðé@example.com", exreg));
            Assert.IsTrue(Regex.IsMatch("üñîçøðé@üñîçøðé.com", exreg));

            //Invalid email addresses[edit]
            Assert.IsFalse(Regex.IsMatch(" ", exreg));
            Assert.IsFalse(Regex.IsMatch("Abc.example.com", exreg));
            Assert.IsFalse(Regex.IsMatch("A@b@c@example.com", exreg));
            Assert.IsFalse(Regex.IsMatch("a\"b(c)d,e:f;g<h>i[j\\k]l@example.com", exreg));
            Assert.IsFalse(Regex.IsMatch("just\"not\"right@example.com", exreg));
            Assert.IsFalse(Regex.IsMatch("this is\"not\allowed@example.com", exreg));
            Assert.IsFalse(Regex.IsMatch("this\\ still\"not\\allowed@example.com", exreg));
            Assert.IsFalse(Regex.IsMatch("john..doe@example.com", exreg));
            Assert.IsFalse(Regex.IsMatch("john.doe@example..com", exreg));
            Assert.IsFalse(Regex.IsMatch("abc", exreg));
            Assert.IsFalse(Regex.IsMatch("abc.@", exreg));
            Assert.IsFalse(Regex.IsMatch("admin@mailserver1", exreg));
        }

        [TestMethod]
        public void TestPhoneRegex()
        {
            var exreg = RegexValidation.Phone;
            //Valid phone address
            Assert.IsTrue(Regex.IsMatch("(+84)0902216369", exreg));
            Assert.IsTrue(Regex.IsMatch("0902216369", exreg));
            Assert.IsTrue(Regex.IsMatch("(+84)0902.216.369", exreg));
            Assert.IsTrue(Regex.IsMatch("+840902.216.369", exreg));
            Assert.IsTrue(Regex.IsMatch("+840902216369", exreg));
        }
    }
}
